/** @file write.S
 *
 * @brief write sycall wrapper
 *
 * @author  
 * 
 */

#include <asm.h>
#include <bits/swi.h>
#include <bits/errno.h>

	.file "write.S"

FUNC(write)
	@ Add code here.  Put your names at the top.
write: 
    @ Save lr to safely go back to the user program
	SWI	WRITE_SWI
	CMP	r0,#0
	BGE	out
	
	LDR	r5, =errno
   	RSB	r0, r0, #0	@ Negate the return value
	STR r0,[r5]		@ Store it in errno 
    MOV	r0, #-1   	@ Return -1
out:
    @ Restore lr and go back to the user program
 	MOV	pc, lr

